$(function () {
  init();

  // js一加载就执行的 方法 入口
  function init() {
    catitems();
    mediaright();

    //设置时间给菜单栏后面4个元素添加隐藏效果
    setTimeout(() => {
      $(".nav_list>li:nth-last-of-type(-n+4)").addClass("mui-hidden");
    }, 200);
  }

  //处理菜单栏渲染
  function catitems() {
    $.ajax({
      url: "http://193.112.55.79:9090/api/getindexmenu",
      type: "get",
      success: function (result) {
        let data = result.result;
        // console.log(data);
        // 要拼接html
        let html = "";

        for (let i = 0; i < data.length; i++) {
          let tmpHtml = `
          <li>
             <a href="javascript:;">
                <p>${data[i].img}</p>
                <p>${data[i].name}</p>
             </a>
          </li>
          `;
          // console.log(${data[i].img})
          html += tmpHtml;
        }

        // 把分类的标签 插入到容器中
        $(".main_nav>.nav_list").html(html);
      }
    });
  }

  //处理折扣详情栏渲染
  function mediaright() {
    $.ajax({
      url: "http://193.112.55.79:9090/api/getmoneyctrl",
      type: "get",
      success: function (result) {
        let data = result.result;
        // console.log(data);
        // 要拼接html
        let html = "";

        for (let i = 0; i < data.length; i++) {
          let tmpHtml = `
          <div class="mmm_media">
            <div class="medialeft"><a href="javascript:;">${data[i].productImgSm}</a></div>
            <div class="mediaright">
                <a href="javascript:;">
                    <h5>${data[i].productName}</h5>
                    <p>${data[i].productPinkage}</p>
                    <span class="from">${data[i].productFrom} | ${data[i].productTime}_</span>
                    <span class="comment"><i class="mui-icon mui-icon-chat"></i>${data[i].productComCount.slice(1,2)}</span>
                </a>
            </div>
        </div>
          `;
          html += tmpHtml;
        }

        // 把分类的标签 插入到容器中
        $(".mmm_recommen").html(html);
      }
    });
  }


  //处理点击回到顶部效果
  let mTop = document.querySelector('.mmm_footer>.mmm_footer_right>a');
  mTop.onclick=function(){
    document.documentElement.scrollTop = 0;
  }

  //处理菜单栏隐藏与显示效果
  // $(".nav_list>li:nth-last-of-type(-n+4)").addClass("mui-hidden");
   $(".nav_list").on('click','li:nth-of-type(8)',function(){
    // console.log('点到我了');
    $(".nav_list>li:nth-last-of-type(-n+4)").toggleClass("mui-hidden");
    // let liHight= $(".nav_list>li:nth-last-of-type(9)").height();
    // console.log(liHight);
  })
})